package com.marlowe.asyouknow.controller;

import com.marlowe.asyouknow.pojo.News;
import com.marlowe.asyouknow.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.client.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @program: as-you-know
 * @description: 新闻controller
 * @author: Marlowe
 * @create: 2020-12-21 11:28
 **/
@Api(tags = "新闻搜索控制类")
@RestController
public class NewsController {
    @Autowired
    private NewsService newsService;

    @ApiOperation(value = "南方周末新闻检索")
    @GetMapping("/news/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize) throws Exception {

        return newsService.searchPageHighlightBuilder(keyword, pageNo, pageSize);
    }

    @ApiOperation(value = "南方周末新闻检索提示")
    @GetMapping("/news/{keyword}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword) throws IOException {
        return newsService.searchSuggestion(keyword);
    }

}
